// 模拟高阶函数 map、every、some

const map = (arr, fn) => {
  let results = []
  for (let value of arr) {
    results.push(fn(value))
  }
  return results
}
// let arr = [1, 2, 3]
// const f = map(arr, v => v * v)
// console.log(f)

const every = (arr, fn) => {
  let result = true
  for (let value of arr) {
    result = fn(value)
    if (!result) {
      break
    }
  }
  return result
}
// let arr = [1, 2, 3]
// const f = every(arr, v => v >= 1)
// console.log(f)

const some = (arr, fn) => {
  let result = false
  for (let value of arr) {
    result = fn(value)
    if (result) {
      break
    }
  }
  return result
}
let arr = [1, 2, 3]
const f = some(arr, v => v % 2 === 0)
console.log(f)